/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;

/**
 *
 * @author MrDoanCoi
 */
import DAL.MyConnectUnit;
import DTO.LoanType_Period;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.HashSet;
public class BLoanType_Period {
    MyConnectUnit connect;
    private Iterable<LoanType_Period> loanType_Periods;
    public BLoanType_Period() {
        this.connect = DAL.DAL.getDAL();
    }
     public HashSet<LoanType_Period>getLoanType_Periods(String condition, String OderBy) throws Exception{
        ResultSet result = this.connect.Select("LoanType_Period",condition,OderBy);
        HashSet<LoanType_Period> loanType_Periodss = new HashSet<LoanType_Period>();
        while(result.next()){
            LoanType_Period loanType_Period = new LoanType_Period();
            loanType_Period.setLoanTypeID(result.getInt("LoanTypeID"));
            loanType_Period.setPeriodID(result.getInt("PeriodID"));
            loanType_Period.setRate(result.getFloat("Rate"));
            loanType_Period.setDescription(result.getString("Description"));
           
            
            loanType_Periodss.add(loanType_Period);
        }
        return loanType_Periodss;
    }
    
  public HashSet<LoanType_Period>getLoanType_Periods(String condition) throws Exception{
        return getLoanType_Periods(condition,null);
    }
  public HashSet<LoanType_Period>getLoanType_Periods() throws Exception{
        return getLoanType_Periods(null);
    }
   
   public LoanType_Period getByID(int id)throws Exception{
        HashSet<LoanType_Period>loanType_Periodss = this.getLoanType_Periods("LoanTypeID = "+ id);
        if(loanType_Periodss.size()>0)
            return loanType_Periodss.toArray(new LoanType_Period[loanType_Periodss.size()])[0];
        return null;
       
   }
   public void Insert(LoanType_Period loanType_Period)throws Exception{
        HashMap<String, Object>map = new HashMap<String,Object>();
        map.put("LoanTypeID", loanType_Period.getLoanTypeID());
        map.put("PeriodID", loanType_Period.getPeriodID());
        map.put("Rate", loanType_Period.getRate());
        map.put("Description", loanType_Period.getDescription());

        this.connect.Insert("LoanType_Period", map);
       
   }
   public void Inserts(HashSet<LoanType_Period> customers)throws Exception{
        for(LoanType_Period loanType_Period:loanType_Periods)
            this.Insert(loanType_Period);
       
   }
   public void Update(LoanType_Period loanType_Period)throws Exception{
        HashMap<String, Object>map = new HashMap<String,Object>();
        map.put("PeriodID", loanType_Period.getPeriodID());
        map.put("Rate", loanType_Period.getRate());
        map.put("Description", loanType_Period.getDescription());
        this.connect.Update("LoanType_Period", map,"LoanTypeID="+loanType_Period.getLoanTypeID());
       
   }
   public void Updates(HashSet<LoanType_Period> loanType_Periods)throws Exception{
        for(LoanType_Period loanType_Period:loanType_Periods)
            this.Update(loanType_Period);
       
   }
   public void Delete(LoanType_Period loanType_Period) throws Exception{
        this.connect.Delete("LoanType_Period", "LoanTypeID="+loanType_Period.getLoanTypeID());
    }
       public void Deletes(HashSet<LoanType_Period> loanType_Periods) throws Exception {
        for(LoanType_Period loanType_Period:loanType_Periods)
            this.Delete(loanType_Period);
   }
    
}
